package com.atguigu.hbase;

import lombok.Getter;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Table;

import java.io.IOException;

public class HbaseConnect {


    @Getter
    static Connection connection=initConnection();

    private static Connection initConnection() {
        Configuration configuration = new Configuration();
        configuration.set("hbase.zookeeper.quorum", "hadoop102,hadoop103,hadoop104");
        configuration.set("hbase.client.ipc.pool.size","10");

        try {
            connection = ConnectionFactory.createConnection(configuration);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return connection;
    }



    public static void main(String[] args) throws IOException {

        Configuration configuration = new Configuration();
        configuration.set("hbase.zookeeper.quorum", "hadoop102,hadoop103,hadoop104");
        configuration.set("hbase.client.ipc.pool.size","10");

        Connection connection = ConnectionFactory.createConnection(configuration);
        System.out.println("connection = " + connection);

    }

    /**
     * 连接关闭方法,用于进程关闭时调用
     * @throws IOException
     */
    public static void closeConnection() throws IOException {
        if (connection != null) {
            connection.close();
        }
    }

}
